-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When C14N fails try comparison without canonicalization #88
base: main
Are you sure you want to change the base?
Conversation
If C14N fails it retry no to text conversion without canonicalization
Codecov Report
@@ Coverage Diff @@
## master #88 +/- ##
=========================================
Coverage 99.30% 99.31%
- Complexity 125 127 +2
=========================================
Files 15 15
Lines 288 291 +3
=========================================
+ Hits 286 289 +3
Misses 2 2
Continue to review full report at Codecov.
|
@sebastianbergmann would you please review this PR or recommend another approach? |
I am sorry but I did not have time yet to look at this. Maybe @theseer can have a look? |
@theseer would you have the chance to take a look on this PR? |
reuse testAssertEqualsSucceeds and testAssertEqualsFails
The more I look at the implementation and how it's growing I'm wondering if it needs to be that complex. Another edge case for instance we're not dealing with currently is in line 86: We now catch the edge case of an empty string returned from Again, do we really need all this complexity? |
I don't know. I think that all this complexity is caused by: Is there any way for There are other issues in the class, like the one you just point out, also PR #71, to test |
@theseer are you interested on this PR? what improvements can I made? |
The issue #87 points out that in some edge cases the C14N can fail.
It is not a common case, even psalm don't recognize that
c14n()
can returnfalse
.This problem can be reproduced by setting a namespace uri value as a defined xml entity.
I append two cases to tests when C14N fails (using current providers):
To solve it, I separate
@$document->loadXML($node->C14N())
into two steps:$c14n = @$node->C14N()
and@$document->loadXML($c14n)
.If
$c14n === false
then retry node to text conversion but without using canonicalization.Observations:
DOMNodeComparator::nodeToText
is always called with$canonicalize = true
,DOMNodeComparator::assertEquals
ignored the$canonicalize
argument.c14n()
call. This is preserving the same behavior as before.If you think is necessary I can try other approaches:
Node canonicalization and xml loading capturing libxml errors, then throw an exception.
This will require to add another exception that contains the
libxml_get_errors()
array, or,implode the errors into a single message and use the current
SebastianBergmann\Comparator\RuntimException
.If convert the node to text fails then throw a
ComparisonFailure
. This is like saying that$expected
is different than$actual
because the comparator is unable to perform the comparison.Change
DOMNodeComparator::acept()
and only return true if objects areDOMNode
and the canonicalization don't fail. I don't like this approach because canonicalization can be very expensive.